//
//  LXFieldAccessView.m
//  TestDemo
//
//  Created by xiao.zhao@lachesis-mh.com on 16/1/6.
//  Copyright © 2016年 xiao.zhao@lachesis-mh.com. All rights reserved.
//

#import "LXFieldAccessView.h"

@interface LXFieldAccessView ()

@end

@implementation LXFieldAccessView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        [self setup];
    }
    
    return self;
}

-(void)setup
{
    self.backgroundColor = kAppThemeColor;
    
    UIButton *leftBtn = [[UIButton alloc]init];
    [leftBtn.titleLabel setFont:[UIFont systemFontOfSize:15.0f]];
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:leftBtn];
    
    _textLabel = [[UILabel alloc]init];
    _textLabel.font = [UIFont lx_boldSystemFontOfSize:17.0f];
    _textLabel.textColor = [UIColor whiteColor];
    _textLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_textLabel];
    
    UIButton *rightBtn = [[UIButton alloc]init];
    [rightBtn.titleLabel setFont:[UIFont systemFontOfSize:15.0f]];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightBtn];
    
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(10.0f);
        make.centerY.equalTo(self.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60.0f, 40.0f));
    }];
    
    [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftBtn.mas_right);
        make.right.equalTo(rightBtn.mas_left);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-10.0f);
        make.centerY.equalTo(self.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60.0f, 40.0f));
    }];
}

-(void)leftAction:(UIButton *)btn
{
    if(_delegate && [_delegate respondsToSelector:@selector(accessView:didClickWithIndex:)])
    {
        [_delegate accessView:self didClickWithIndex:1];
    }
}

-(void)rightAction:(UIButton *)btn
{
    if(_delegate && [_delegate respondsToSelector:@selector(accessView:didClickWithIndex:)])
    {
        [_delegate accessView:self didClickWithIndex:2];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
